import request from "./index";

// 用户登录
export function login(data) {
    return request({
        url: "/user/login",
        method: "post",
        data,
    });
}

// 用户注册
export function register(data) {
    return request({
        url: "/user/register",
        method: "post",
        data,
    });
}

// 获取用户信息
export function getUserInfo(userId) {
    return request({
        url: `/user/info${userId ? `/${userId}` : ""}`,
        method: "get",
    });
}

// 更新用户信息
export function updateUserInfo(data) {
    return request({
        url: "/user/info",
        method: "put",
        data,
    });
}

// 更新用户头像
export function updateAvatar(data) {
    return request({
        url: "/user/avatar",
        method: "post",
        headers: {
            "Content-Type": "multipart/form-data",
        },
        data,
    });
}

// 修改密码
export function changePassword(data) {
    return request({
        url: "/user/password",
        method: "put",
        data,
    });
}

// 获取用户收藏列表
export function getUserCollections(params) {
    return request({
        url: "/user/collections",
        method: "get",
        params,
    });
}

// 添加收藏
export function addCollection(data) {
    return request({
        url: "/user/collections",
        method: "post",
        data,
    });
}

// 取消收藏
export function removeCollection(id) {
    return request({
        url: `/user/collections/${id}`,
        method: "delete",
    });
}

// 获取用户操作日志
export function getUserLogs(params) {
    return request({
        url: "/user/logs",
        method: "get",
        params,
    });
}

// 退出登录
export function logout() {
    return request({
        url: "/user/logout",
        method: "post",
    });
}
